home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_misc / tnc1stuf.lzh / TNC1CAL.ASM < prev    next >
Assembly Source File  |  1987-05-26  |  8KB  |  339 lines

  1.     title    "TNC1 TONE CALIBRATOR"
  2.  
  3. * Tone calibration helper program for the TAPR TNC1
  4. * Written by Marc Kaufman, WB6ECE
  5. *    March 1987
  6.  
  7. * How to use this program:
  8. *
  9. *    Load it using the TNCBUG boot loader.
  10. *    Set the TNC jumpers as follows -
  11. *
  12. *        Remove JP1    (use it for JP2 or JP3)
  13. *        Install JP2 - for measurement of FSK output tones
  14. *    or    Install JP3 - for measurement of receive center tone
  15. *
  16. *    Type 'G' to start program.
  17. *    The program will continuously print out changing tone values,
  18. *      directly in Hz.  Adjust the appropriate pot
  19. *        R38 - low tone
  20. *        R36 - high tone
  21. *        R43 - receiver center
  22. *
  23. *    Typing 'T' will toggle between low and high tones (low is first)
  24. *    Typing 'K' will key and un-key the transmit line.
  25. *      This is for adjusting muting of the FSK output (R31)
  26. *      and audio level (R33)
  27. *
  28. *    Typing <carriage-return> will return to TNCBUG
  29.  
  30. * Modification for Fast TNC
  31. *
  32. *    This program is defaulted for the Slow 6809.
  33. *    To reassemble for the Fast 6809, set the equate below to:
  34. *
  35. *        fast equ 1
  36. *
  37. *    If you don't want to do that, just divide the displayed values by 2.
  38.  
  39. fast    equ    0        default is slow
  40. *
  41.  
  42. * Hardware addresses
  43.  
  44. acia    equ    $2010        6551 UART
  45. acchar    equ    acia
  46. acstat    equ    acia+1
  47. accmnd    equ    acia+2
  48. acctrl    equ    acia+3
  49.  
  50. pia    equ    $2020        6520 parallel output
  51. pra    equ    pia        register A
  52. pcra    equ    pia+1        control A
  53. prb    equ    pia+2        register B
  54. pcrb    equ    pia+3        control B
  55.  
  56. via    equ    $2040        6522 timer chip
  57. vorb    equ    via        output register B
  58. vira    equ    via+1        input register A
  59. vora    equ    via+15        output register A, no handshake
  60. vddrb    equ    via+2        data direction register B
  61. vddra    equ    via+3        data direction register A
  62. vtim1cl    equ    via+4        low byte of timer 1 counter
  63. vtim1ch    equ    via+5        high byte of timer 1 counter
  64. vtim1ll    equ    via+6        low byte of timer 1 latch
  65. vtim1lh    equ    via+7        high byte of timer 1 latch
  66. vtim2l    equ    via+8        low byte of timer 2
  67. vtim2h    equ    via+9        high byte of timer 2
  68. vsr    equ    via+10        shift register
  69. vacr    equ    via+11        auxiliary control register
  70. vpcr    equ    via+12        peripheral control register
  71. vifr    equ    via+13        interrupt flag register
  72. vier    equ    via+14        interrupt enable register
  73.  
  74. timrc1    equ    vtim1cl        both bytes of timer 1 counter
  75. timer2    equ    vtim2l        both bytes of timer2
  76.  
  77. *    NOTE: this chip inverts Addresses and Data!!!
  78. hdlc    equ    $2800        WD 1933 HDLC chip
  79. hcr1    equ    hdlc+7        control register 1
  80. hcr2    equ    hdlc+6        control register 2
  81. hcr3    equ    hdlc+5        control register 3
  82. hrhr    equ    hdlc+4        receive holding register
  83. hthr    equ    hdlc+3        transmit holding register
  84. hir    equ    hdlc+3        interrupt register
  85. hsr    equ    hdlc+2        status register
  86.  
  87. ram    equ    $0000        bank 0 ram ($0000 - $1fff)
  88. ram1    equ    $4000        bank 1 ram ($4000 - $5fff)
  89. rom    equ    $e000        top rom    ($e000 - $ffff)
  90.  
  91. CR    equ    $0d        carriage return
  92. LF    equ    $0a        line feed
  93.  
  94. *
  95.     dsect
  96.     org    ram        data starts in low ram
  97.  
  98. * interrupt re-vector area: parallel to fff0-ffff
  99.  
  100. igo    fdb    calib        0000 - program start point
  101. iswi3    rmb    2        0002
  102. iswi2    rmb    2        0004
  103. ifirq    rmb    2        0006
  104. iirq    fdb    ctime        0008
  105. iswi    rmb    2        000a
  106. inmi    rmb    2        000c - last vector used
  107. ireset    rmb    2        full reset
  108.  
  109. stack    equ    $ff        my stack is above debug stack
  110.     org    $100        local data starts at direct page 1
  111.  
  112. svint    fcb    0
  113. svchr    fcb    0
  114. dcount    fcb    0        divide loop counter
  115. quot    fdb    0,0        32 bit dividend / quotient
  116. div    fdb    0        16 bit divisor (delta)
  117. addr    fdb    0        output value
  118. oldval    fdb    0        previous timer value
  119. delta    fdb    0        delta timer value
  120. flag    fcb    0        flag from interrupt that delta set
  121. oldtone    fcb    $ce        vpcr flag (ca2 = 1, cb2 = 0))
  122. oldkey    fcb    $ff        key output (misc 0 bit)
  123.  
  124.  
  125. calib    lda    #1        dp page 1
  126.     tfr    A,DP
  127.     lds    #stack        set up program stack
  128.  
  129.     lda    #$0b        make sure acia doesn't interrupt
  130.     sta    accmnd
  131.     lda    <oldkey
  132.     sta    hcr1        set initial hdlc mode
  133.  
  134.     lda    #$f0
  135.     sta    vora
  136.     sta    vddra
  137.     lda    #$3f
  138.     sta    vorb
  139.     sta    vddrb        make sure pb6 and pb7 are inputs
  140.     lda    <oldtone
  141.     sta    vpcr
  142.     lda    #$20        00 1 000 0 0 = timer modes
  143.     sta    vacr
  144.     lda    #$7f
  145.     sta    vier        disable all interrupts
  146.     lda    #$80+$20    timer2 interrupt bit
  147.     sta    vier        enable interrupt
  148.     ldx    #$ffff
  149.     stx    timrc1        initialize timer 1 free run
  150.     ldx    #$0100        = count of 1 because of flipped order
  151.     stx    timer2        restart interrupt and count
  152.     cli            enable 6809 interrupts
  153.  
  154.     clr    <flag        wait for count
  155.     bsr    test        check acia, wait for flag
  156.     clr    <flag
  157. mon    bsr    test        wait for flag
  158.     ldd    <delta
  159.     std    <div        +delta, divisor
  160.  
  161.     lsra            delta/2 for rounding
  162.     rorb
  163.     std    <quot+2
  164.     ldd    #$01c2        (32 * 921600 Hz) / (32 * delta)
  165.     std    <quot
  166.     lda    #17
  167.     sta    <dcount        divide takes 17 iterations
  168.  
  169. div32    ldd    <quot
  170.     subd    <div
  171.     bcs    .l1        overshoot, ignore subtraction
  172.     std    <quot
  173. .l1    tfr    CC,A        complement carry bit
  174.     eora    #1
  175.     tfr    A,CC
  176.     lda    #4        set for shift
  177.     ldx    #quot+4
  178. shft    ldb    0,-x
  179.     rolb
  180.     stb    0,x
  181.     deca
  182.     bne    shft        loop through 4 bytes
  183.     dec    <dcount        main iteration loop
  184.     bne    div32
  185.  
  186.     ldx    <quot+2        result
  187.     cmpx    <addr        previous result
  188.     beq    mon        no change
  189.     stx    <addr        new value
  190.     jsr    echoa        print it
  191.     bra    mon
  192.  
  193. * interrupt routine
  194. *
  195. ctime    lda    hir        clear possible hdlc interrupt
  196.     lda    vifr        save interrupt flag value
  197.     sta    <svint
  198.     bpl    ctimex        no interrupt
  199.  
  200.     ldd    timrc1        timer 1 counter value
  201.     tsta
  202.     bne    .l2        correct value on 8 bit overflow
  203.     incb
  204. .l2    exg    A,B        put in hi-low order
  205.     tfr    D,X        save value
  206.     ldd    <oldval        get 'old' old value
  207.     stx    <oldval        save 'new' old value
  208.     subd    <oldval        delta-t
  209.     std    <delta
  210.     inc    <flag
  211.     ldx    #$1f00-fast*$1000    = count of 32 (slow) or 16 (fast)
  212.     stx    timer2        restart interrupt and count
  213. ctimex    rti            return
  214.  
  215. * test - wait for flag, and answer acia commands
  216. *
  217. test    ldb    acstat
  218.     bitb    #$08
  219.     beq    .l3        no character
  220.     jsr    arcv        get character
  221.     cmpb    #'K'
  222.     beq    key
  223.     cmpb    #'T'
  224.     beq    tone
  225.     cmpb    #CR
  226.     bne    .l3        ignore all others
  227.     lda    #$ff        turn off any keying
  228.     sta    hcr1
  229.     swi            return to debug
  230.  
  231. .l3    tst    <flag
  232.     beq    test        no flag, continue to wait
  233.     rts            exit on flag
  234.  
  235. key    lda    <oldkey        toggle keying flag
  236.     eor a    #1
  237.     sta    <oldkey
  238.     sta    hcr1
  239.     bra    .l3
  240.  
  241. tone    lda    <oldtone
  242.     eora    #$20        toggle tone bit (cb2)
  243.     sta    <oldtone
  244.     sta    vpcr
  245.     bra    .l3
  246.  
  247.  
  248. * ASEND - send one character to acia (busy wait)
  249. *    enter - character in A
  250. *
  251. asend    ldb    acstat
  252.     bitb    #$10
  253.     beq    asend        wait for previous character to clear
  254.     sta    acchar        send this one
  255.     rts
  256.  
  257. * ACRLF - print cr,lf
  258. *
  259. acrlf    lda    #CR        cr
  260.     bsr    asend
  261.     lda    #LF        lf
  262.     bra    asend
  263.  
  264. * OUT2H - put out hex digit (2 output bytes)
  265. *    entry - address of byte in X
  266. *
  267. out2h    lda    0,x+
  268. out2ha    sta    <svchr
  269.     bsr    outhl        output left digit
  270.     lda    <svchr
  271.     bra    outrl        output right digit
  272.  
  273. *
  274. outhl    lsra            output left hex digit
  275.     lsra
  276.     lsra
  277.     lsra
  278. outrl    anda    #$f        output right hex digit
  279.     adda    #'0'
  280.     cmpa    #'9'
  281.     bls    asend        0-9
  282.     adda    #'A'-'9'-1
  283.     bra    asend        A-F
  284.  
  285. *
  286. out4hs    bsr    out2h        output 2 bytes plus space
  287. out2hs    bsr    out2h        output 1 byte plus space
  288. outs    lda    #' '
  289.     bra    asend
  290.  
  291. out8hs    bsr    o4h        output 4 bytes separated by spaces
  292. o4h    bsr    out2hs
  293.     bra    out2hs
  294.  
  295. echoa    ldd    <addr        print decimal value
  296.     ldx    #dectab        table of decimal powers
  297. echol    ldy    0,X        examine entry
  298.     beq    echod        done (zero)
  299.     clr    <svchr
  300. echoi    subd    0,X
  301.     bmi    echoj        overflow
  302.     inc    <svchr        count
  303.     bra    echoi
  304.  
  305. echoj    addd    0,X++        restore and point to next
  306.     tfr    D,Y        save value
  307.     lda    <svchr
  308.     adda    #'0'        convert count to digit
  309.     bsr    asend
  310.     tfr    Y,D
  311.     bra    echol
  312.  
  313. echod    bra    acrlf        print cr-lf after
  314.  
  315. dectab    fdb    1000
  316.     fdb    100
  317.     fdb    10
  318.     fdb    1
  319.     fdb    0
  320.  
  321. * ARCV - wait for and read one character from acia
  322. *    exit - character in A (8 bits)
  323. *        character in B (masked to 7 bits and upper case)
  324. *
  325. arcv    ldb    acstat
  326.     bitb    #$08
  327.     beq    arcv        wait for character to arrive
  328.     lda    acchar
  329.     tab
  330.     andb    #$7f
  331.     cmpb    #'a'
  332.     blt    .arcvx        not alphabetic
  333.     cmpb    #'z'
  334.     bgt    .arcvx
  335.     subb    #'a'-'A'    convert to upper case
  336. .arcvx    rts
  337.  
  338.     end
  339.